home *** CD-ROM | disk | FTP | other *** search
- #include "Protocol.h"
-
- /*#define APPLUTIL {dummy}*/
-
- char bEleven;
- ProtoRecHandle blPRH;
-
- #ifndef APPLUTIL
- #include <:Mac #includes:SetUpA4.h>
- #endif
-
- #ifndef APPLUTIL
- pascal OsErr main(message, prp, refCon)
- #else
- pascal OsErr UtilityMain(message, prp, refCon)
- #endif
- register int message;
- register ProtoRecPtr prp;
- long refCon;
- {
- OsErr err = noErr;
- ProcMenuHandle BuildProcMenu();
- #ifndef APPLUTIL
- RememberA0();
- SetUpA4();
- #endif
- switch(message) {
- case BUILDTMENU:
- case BUILDDAMENU:
- case BUILDMENU:
- /* ProcMenuHandle returned in prp, refCon contains
- Transfer menu ID in hi word and mode in low word.
- */
- *((ProcMenuHandle *) prp) =
- BuildProcMenu(message, HiWord(refCon), LoWord(refCon));
- break;
- case ABLEMENU:
- if (prp) {
- doEDItems(prp, (refCon != 0L));
- }
- break;
- case DISPOSEMENU:
- if (prp) {
- doKillMenu(prp);
- }
- break;
- case DISPOSEPREC:
- if (prp) {
- doKillPRec(prp);
- }
- break;
- case DOMENU:
- if (prp) {
- doMenu(prp, HiWord(refCon), LoWord(refCon));
- }
- break;
- }
- #ifndef APPLUTIL
- RestoreA4();
- #endif
- return(err);
- }
-
- setFolder(mode)
- int mode;
- {
- Point xyloc;
- SFReply reply;
- char vName[64];
- long CurDirSave;
- int DiskSave, vRef;
- UtilPrefHandle UPH;
- pascal int sfHook();
- pascal char sfFilter();
- register UtilPrefPtr upp;
- CurDirSave = CurDirStore;
- DiskSave = SFSaveDisk;
- DLOGSetPt(900, &xyloc);
- bEleven = FALSE;
- #ifndef APPLUTIL
- RememberA4();
- #endif
- SFPGetFile(xyloc, 0L, sfFilter, -1, 0L, sfHook, &reply, 900, 0L);
- if (bEleven) {
- /* save the directory information */
- UPH = (UtilPrefHandle) GetResource('DATA', 900);
- if (UPH) {
- HLock(UPH);
- upp = *UPH;
- if (mode == BBSMODE) {
- ++upp;
- }
- /* get the volume name in a round about way */
- GetVol(vName, &vRef);
- SetVol(0L, -SFSaveDisk);
- GetVol(upp->vName, &upp->CurDirStore);
- upp->CurDirStore = CurDirStore;
- SetVol(vName, vRef);
- HUnlock(UPH);
- ChangedResource(UPH);
- WriteResource(UPH);
- }
- }
- CurDirStore = CurDirSave;
- SFSaveDisk = DiskSave;
- }
-
- pascal char sfFilter(pBlock)
- ParmBlkPtr pBlock;
- {
- /* never open any files */
- return((char) TRUE);
- }
-
- pascal int sfHook(item, dp)
- int item;
- DialogPtr dp;
- {
- #ifndef APPLUTIL
- SetUpA4();
- #endif
- switch(item) {
- case -1:
- SetCtlTitle(11, "\pSet", dp);
- break;
- /* Set */
- case 11:
- bEleven = TRUE;
- item = 1;
- break;
- }
- #ifndef APPLUTIL
- RestoreA4();
- #endif
- return(item);
- }
-
- doMenu(PMH, menuID, menuItem)
- ProcMenuHandle PMH;
- register int menuID;
- register int menuItem;
- {
- int pmID, OK, vRef;
- ProtoRecHandle PRH;
- register int i, hID;
- register ProcMenuPtr pmp;
- register ProtoRecPtr prp;
- pmp = *PMH;
- pmID = (*pmp->pMenu)->menuID;
- /* find the matching entry */
- for (i = 0; i<pmp->pCount; i++) {
- if (pmID == menuID) {
- /* look at the itemID */
- if (pmp->pList[i].itemID == menuItem) {
- break;
- }
- }
- else {
- /* look for hierarchical menu item and hierarchical ID */
- if ((pmp->pList[i].HitemID == menuItem) &&
- (pmp->pList[i].HmenuID == menuID)) {
- break;
- }
- }
- }
- if (i < pmp->pCount) {
- /* we found a match so let's do it */
- /* start by building a ProtoRec */
- PRH = (ProtoRecHandle) NewHandle((long) sizeof(ProtoRec));
- pmp = *PMH;
- if (PRH) {
- prp = *PRH;
- if (pmp->pList[i].funcMask & (CANSEN+CANBSEN)) {
- pmp->transMessage = SEND;
- }
- else if (pmp->pList[i].funcMask & (CANREC+CANBREC)) {
- pmp->transMessage = RECEIVE;
- }
- else {
- pmp->transMessage = SETPREFS;
- }
- pmp->transRefCon = pmp->pList[i].refCon;
- pmp->transIndex = i;
- /* prp->mRefIn, mRefOut, timeOut to be filled out by caller */
- prp->procID = pmp->pList[i].procID;
- prp->protoData = 0L;
- prp->errReason = 0L;
- prp->fileCount = 0;
- prp->filesDone = 0;
- prp->bytesDone = 0L;
- prp->bytesTotal = 0L;
- prp->F.word = 0;
- prp->F.B.useMacBinary = TRUE;
- prp->F.B.transMode = pmp->pMode;
- HLock(PMH);
- OK = TRUE;
- switch(pmp->transMessage) {
- case SETPREFS:
- (*PRH)->fileCount = 0;
- break;
- case SEND:
- /* get list of files to send */
- OK = getTransList(PRH, pmp->pList[i].pFlags & CANBSEN);
- break;
- case RECEIVE:
- /* get a working directory for the receive folder */
- getVRef(&vRef, (*PRH)->F.B.transMode);
- if ((*PRH)->F.B.transMode == BBSMODE) {
- if (pmp->pList[i].pFlags & CANBREC) {
- /* set up batch receive test files */
- addName(PRH, vRef, "\pBBS Batch Upload A", 0L,
- pmp->pList[i].pFlags & CONTREC);
- addName(PRH, vRef, "\pBBS Batch Upload B", 0L,
- pmp->pList[i].pFlags & CONTREC);
- addName(PRH, vRef, "\pBBS Batch Upload C", 0L,
- pmp->pList[i].pFlags & CONTREC);
- }
- else {
- /* set up receive files for BBS */
- addName(PRH, vRef, "\pBBS Upload", 0L,
- pmp->pList[i].pFlags & CONTREC);
- }
- }
- else {
- /* set up receive folder for terminal */
- addName(PRH, vRef, "\pDownload File", 0L,
- pmp->pList[i].pFlags & CONTREC);
- }
- break;
- }
- HUnlock(PMH);
- MoveHHi(PRH);
- HLock(PRH);
- pmp = *PMH;
- pmp->transData = PRH;
- (*PRH)->startTime = TickCount();
- if (!OK) {
- /* Dispose of everyting we created */
- doKillPRec(PMH);
- }
- }
- }
- else if (menuItem == pmp->foldID) {
- setFolder(pmp->pMode);
- }
- else if (menuItem == pmp->helpID) {
- doHelp(pmp->doUpdate);
- }
- }
-
- int getTransList(prh, batch)
- register ProtoRecHandle prh;
- int batch;
- {
- int i = 1;
- Point xyloc;
- SFReply reply;
- Str255 text1, text2;
- pascal int blHook();
- pascal char blFilter();
- blPRH = prh;
- do {
- DLOGSetPt(900, &xyloc);
- bEleven = FALSE;
- if (!batch) {
- bEleven = -1;
- }
- #ifndef APPLUTIL
- RememberA4();
- #endif
- SFPGetFile(xyloc, 0L, blFilter, -1, 0L, blHook, &reply, 900, 0L);
- if (reply.good) {
- /* add name to list */
- if ((*prh)->F.B.transMode == BBSMODE) {
- /* fill in MacBinary names */
- Pstrcpy(text1, "\pMacBinary Name ");
- NumToString((long) i++, text2);
- Pstrcat(text1, text2);
- addName(prh, reply.vRefNum, reply.fName, text1, -1);
- }
- else {
- addName(prh, reply.vRefNum, reply.fName, 0L, -1);
- }
- }
- } while (bEleven == TRUE);
- return(reply.good);
- }
-
- pascal char blFilter(pBlock)
- ParmBlkPtr pBlock;
- {
- char noShow;
- register int i;
- register FListPtr flp;
- #ifndef APPLUTIL
- SetUpA4();
- #endif
- noShow = FALSE;
- flp = (*blPRH)->fList;
- for (i = 0; i<(*blPRH)->fileCount; i++) {
- if (EqualString(*flp[i].fName, pBlock->fileParam.ioNamePtr, TRUE, TRUE)) {
- noShow = TRUE;
- break;
- }
- }
- #ifndef APPLUTIL
- RestoreA4();
- #endif
- return(noShow);
- }
-
- pascal int blHook(item, dp)
- int item;
- DialogPtr dp;
- {
- #ifndef APPLUTIL
- SetUpA4();
- #endif
- switch(item) {
- case -1:
- SetCtlTitle(1, "\pSend", dp);
- SetCtlTitle(11, "\pBatch", dp);
- if (bEleven < 0) {
- ActItem(11, FALSE, dp);
- }
- break;
- /* Set */
- case 11:
- bEleven = TRUE;
- item = 1;
- break;
- }
- #ifndef APPLUTIL
- RestoreA4();
- #endif
- return(item);
- }
-
- addName(prh, vRef, fName, bName, recover)
- register ProtoRecHandle prh;
- int vRef;
- StringPtr fName, bName;
- int recover;
- {
- OsErr err;
- FInfo fInfo;
- FListRec FLR;
- register int i;
- WDPBRec myWDPBRec;
- Str255 text2, text1;
- Pstrcpy(text2, fName);
- i = 0;
- FLR.mbName = 0L;
- FLR.vRefNum = vRef;
- FLR.dirID = 0L;
- FLR.fileID = 0L;
- if (recover >=0 ) {
- for (;;) {
- err = GetFInfo(text2, FLR.vRefNum, &fInfo);
- if (err) {
- break;
- }
- if ((i == 0) && recover && (fInfo.fdType == 'FRAG')) {
- break;
- }
- ++i;
- NumToString((long) i, text1);
- Pstrcpy(text2, fName);
- Pstrcad(text2, ' ');
- Pstrcat(text2, text1);
- }
- }
- FLR.fName = NewString(text2);
- if (bName) {
- FLR.mbName = NewString(bName);
- }
- else {
- FLR.mbName = 0L;
- }
- /* convert the working directory into a dirID */
- myWDPBRec.ioCompletion = 0L;
- myWDPBRec.ioNamePtr = 0L;
- myWDPBRec.ioVRefNum = FLR.vRefNum;
- myWDPBRec.ioWDIndex = 0;
- myWDPBRec.ioWDProcID = 0L;
- myWDPBRec.ioWDVRefNum = 0;
- myWDPBRec.ioWDDirID = 0L;
- err = PBGetWDInfo(&myWDPBRec, FALSE);
- if (!err) {
- FLR.dirID = myWDPBRec.ioWDDirID;
- }
- SetHandleSize(prh, GetHandleSize(prh)+sizeof(FListRec));
- (*prh)->fList[(*prh)->fileCount] = FLR;
- ++(*prh)->fileCount;
- }
-
- getVRef(vRefPtr, mode)
- register int *vRefPtr;
- int mode;
- {
- int vRef;
- OsErr err;
- WDPBRec myWDPBRec;
- UtilPrefHandle UPH;
- register UtilPrefPtr upp;
- /* get the vRefNum from the DATA resource */
- *vRefPtr = 0;
- UPH = (UtilPrefHandle) GetResource('DATA', 900);
- if (UPH) {
- HLock(UPH);
- upp = *UPH;
- if (mode == BBSMODE) {
- ++upp;
- }
- /* open a working directory */
- myWDPBRec.ioCompletion = 0L;
- myWDPBRec.ioNamePtr = 0L;
- GetVol(0L, &vRef);
- SetVol(&upp->vName, 0);
- GetVol(0L, &myWDPBRec.ioVRefNum);
- SetVol(0L, vRef);
- myWDPBRec.ioWDProcID = 'ERIK';
- myWDPBRec.ioWDDirID = upp->CurDirStore;
- err = PBOpenWD(&myWDPBRec, FALSE);
- if (!err) {
- *vRefPtr = myWDPBRec.ioVRefNum;
- }
- HUnlock(UPH);
- }
- }
-
- doKillPRec(pmh)
- register ProcMenuHandle pmh;
- {
- register int i;
- register ProtoRecPtr prp;
- if ((*pmh)->transData) {
- prp = *(*pmh)->transData;
- for (i = 0; i<prp->fileCount; i++) {
- if (prp->fList[i].fName) {
- DisposHandle(prp->fList[i].fName);
- }
- if (prp->fList[i].mbName) {
- DisposHandle(prp->fList[i].mbName);
- }
- }
- HUnlock((*pmh)->transData);
- DisposHandle((*pmh)->transData);
- (*pmh)->transData = 0L;
- }
- }
-
- doKillMenu(pmh)
- register ProcMenuHandle pmh;
- {
- register int i, hID;
- register MenuHandle hmh;
- for (i = (*pmh)->firstID; i<=(*pmh)->helpID; i++) {
- DelMenuItem((*pmh)->pMenu, (*pmh)->firstID);
- }
- for (i = 0; i<(*pmh)->pCount; i++) {
- hID = (*pmh)->pList[i].HmenuID;
- if ((*pmh)->pList[i].HitemID == 1) {
- hmh = GetMHandle(hID);
- DeleteMenu(hID);
- DisposeMenu(hmh);
- }
- DisposHandle((*pmh)->pList[i].subName);
- }
- DisposHandle((*pmh)->autoComs);
- DisposHandle(pmh);
- }
-
- doEDItems(pmh, state)
- register ProcMenuHandle pmh;
- register int state;
- {
- register int i;
- register MenuHandle pMenu;
- pMenu = (*pmh)->pMenu;
- for (i = 0; i<(*pmh)->pCount; i++) {
- EDItem(pMenu, (*pmh)->pList[i].itemID, state);
- }
- EDItem(pMenu, (*pmh)->foldID, state);
- EDItem(pMenu, (*pmh)->helpID, state);
- }
-
- EDItem(menu, item, state)
- MenuHandle menu;
- int item, state;
- {
- if (state) {
- EnableItem(menu, item);
- }
- else {
- DisableItem(menu, item);
- }
- }
-
- ProcMenuHandle BuildProcMenu(message, pMenuID, mode)
- int message;
- int pMenuID;
- int mode;
- {
- int hBase;
- MenuHandle pMenu;
- register ProcMenuHandle pmh;
- pMenu = GetMHandle(pMenuID);
- pmh = (ProcMenuHandle) NewHandle((long) sizeof(ProcMenu));
- (*pmh)->doUpdate = 0L;
- (*pmh)->pMode = mode;
- (*pmh)->pMenu = pMenu;
- (*pmh)->transData = 0L;
- (*pmh)->pCount = 0;
- (*pmh)->firstID = CountMItems(pMenu)+1;
- (*pmh)->foldID = CountMItems(pMenu);
- (*pmh)->autoCount = 0;
- (*pmh)->autoComs = (AutoComHandle) NewHandle(0L);
- if (message == BUILDDAMENU) {
- /* DAs can have hierarchical menu IDs from 236 to 255 */
- /* ALL OF THESE IDs MIGHT BE USED BY PROTOCOLS!!!! */
- hBase = 236;
- }
- else {
- /* applications can have hierarchical menu IDs from 0 to 235 */
- /* OF WHICH 216 TO 235 MIGHT BE USED BY PROTOCOLS!!!! */
- hBase = 216;
- }
- if ((message == BUILDTMENU) || (mode == TERMINALMODE) ||
- (message == BUILDDAMENU)) {
- /* add all possible protocols */
- AddProcSubs(CANSEN+CANBSEN, pmh, hBase);
- if (mode == TERMINALMODE) {
- AddProcSubs(CANREC, pmh, hBase);
- AddProcSubs(SETERMPREF, pmh, hBase);
- }
- else {
- AddProcSubs(CANREC+CANBREC, pmh, hBase);
- AddProcSubs(SETBBSPREF, pmh, hBase);
- }
- if ((*pmh)->foldID) {
- (*pmh)->foldID += 2;
- (*pmh)->helpID = (*pmh)->foldID+2;
- AppendMenu(pMenu, "\p(-;Set Receive Folder;(-;Help");
- }
- }
- else {
- /* only add the prefs and help items in BBS mode */
- AddProcSubs(SETERMPREF, pmh, hBase);
- if ((*pmh)->foldID) {
- (*pmh)->foldID += 2;
- (*pmh)->helpID = (*pmh)->foldID;
- (*pmh)->foldID = -1;
- AppendMenu(pMenu, "\p(-;Help");
- }
- }
- return(pmh);
- }
-
- int AddProcSubs(mask, pmh, hBase)
- int mask;
- ProcMenuHandle pmh;
- int hBase;
- {
- ProcSub SF;
- ResType rType;
- PInfHandle pHand;
- MenuHandle hMenu;
- char needBar, newItem;
- Str255 rName, lastName;
- register ProcMenuPtr pmp;
- int pID, hID, firstID, itemID, subCount, hCount, i, j;
- HLock(pmh);
- pmp = *pmh;
- firstID = pmp->foldID;
- needBar = (pmp->foldID != 0);
- /* loop through all of the possible PROC IDs */
- for (i = 0; i<PROCINDEX; i++) {
- pID = i*100+1000;
- hID = i+hBase;
- if (mask & (CANREC+CANBREC)) {
- hID += PROCINDEX;
- }
- pHand = (PInfHandle) Get1Resource('PInf', pID);
- if (pHand) {
- hCount = 0;
- hMenu = 0L;
- newItem = FALSE;
- itemID = pmp->foldID;
- subCount = (*pHand)->SubCount;
- GetResInfo(pHand, &pID, &rType, rName);
- for (j = 0; j<subCount; j++) {
- GetSubFunction(&SF, pID, j+1);
- if (rName[0] && SF.subName[0] && (mask & SF.pFlags)) {
- ++hCount;
- if (needBar) {
- /* add a split bar */
- ++itemID;
- ++firstID;
- ++pmp->foldID;
- AppendMenu(pmp->pMenu, "\p(-"); /* ) */
- needBar = FALSE;
- }
- /* first, add this to the PROC menu list */
- HUnlock(pmh);
- SetHandleSize(pmh, GetHandleSize(pmh)+sizeof(ProcList));
- HLock(pmh);
- pmp = *pmh;
- pmp->pList[pmp->pCount].procID = pID;
- pmp->pList[pmp->pCount].itemID = itemID+1;
- pmp->pList[pmp->pCount].subName = NewString(SF.subName);
- pmp->pList[pmp->pCount].funcMask = mask;
- pmp->pList[pmp->pCount].pFlags = SF.pFlags;
- pmp->pList[pmp->pCount].refCon = SF.refCon;
- if (SF.autoCom[0] && (mask & CANREC+CANBREC)) {
- addAutoCom(pmp, (*pmp->pMenu)->menuID, itemID+1, SF.autoCom);
- }
- if (hCount > 1) {
- if (hCount == 2) {
- /* make hierarchical menu for last choice */
- pmp->pList[pmp->pCount-1].HmenuID = hID;
- pmp->pList[pmp->pCount-1].HitemID = 1;
- hMenu = NewMenu(hID, rName);
- /* add a new hierarchical menu item and stop any
- funny business
- */
- AppendMenu(hMenu, "\pJR Was Here");
- /* hierarchical item text comes from PInf resource */
- Pstrcad(lastName, '…');
- SetItem(hMenu, 1, lastName);
- InsertMenu(hMenu, -1);
- /* adjust any auto receive commands */
- swapAutoCom(pmp, (*pmp->pMenu)->menuID, itemID+1,
- hID, 1);
- }
- pmp->pList[pmp->pCount].HmenuID = hID;
- pmp->pList[pmp->pCount].HitemID = hCount;
- /* add a new hierarchical menu item and stop any
- funny business
- */
- AppendMenu(hMenu, "\pJR Was Here");
- /* hierarchical item text comes from PInf resource */
- Pstrcad(SF.subName, '…');
- SetItem(hMenu, hCount, SF.subName);
- /* adjust any auto receive commands */
- swapAutoCom(pmp, (*pmp->pMenu)->menuID, itemID+1,
- hID, hCount);
- }
- else {
- pmp->pList[pmp->pCount].HmenuID = 0;
- pmp->pList[pmp->pCount].HitemID = 0;
- }
- if (hCount == 1) {
- newItem = TRUE;
- ++pmp->foldID;
- /* add a new main menu item and stop any funny business */
- AppendMenu(pmp->pMenu, "\pJR Was Here");
- /* main item text comes from PInf resource name */
- lastName[0] = 0;
- if (mask & (CANSEN+CANBSEN)) {
- /* add Send prefix */
- Pstrcpy(lastName, "\pSend ");
- }
- else if (mask & (CANREC+CANBREC)) {
- /* add Receive prefix */
- Pstrcpy(lastName, "\pReceive ");
- }
- else if (mask & (SETERMPREF+SETBBSPREF)) {
- /* add Set prefix */
- Pstrcpy(lastName, "\pSet ");
- }
- Pstrcat(lastName, rName);
- Pstrcpy(rName, lastName);
- SetItem(pmp->pMenu, pmp->foldID, rName);
- }
- Pstrcpy(lastName, SF.subName);
- ++pmp->pCount;
- }
- }
- if (newItem) {
- if (hMenu) {
- SortProcMenu(pmp, hMenu, 1, hCount);
- SetItemCmd(pmp->pMenu, pmp->foldID, 0x1B);
- SetItemMark(pmp->pMenu, pmp->foldID, hID);
- }
- else {
- /* tack a … on to the end of the menu item */
- Pstrcad(rName, '…');
- SetItem(pmp->pMenu, pmp->foldID, rName);
- }
- }
- /* we are not going to use 'PInf' again... */
- ReleaseResource(pHand);
- }
- }
- SortProcMenu(pmp, pmp->pMenu, firstID, pmp->foldID);
- HUnlock(pmh);
- }
-
- SortProcMenu(pmp, pMenu, fromItem, toItem)
- register ProcMenuPtr pmp;
- MenuHandle pMenu;
- int fromItem, toItem;
- {
- Str255 itemText1, itemText2;
- int done, mark1, mark2, cmd1, cmd2;
- int jump, n, i, j, k, mID, pmID, item1, item2;
- mID = (*pMenu)->menuID;
- pmID = (*pmp->pMenu)->menuID;
- /* remember to move command AND mark keys too */
- n = toItem-fromItem+1;
- jump = n;
- while (jump > 1) {
- jump /= 2;
- do {
- done = TRUE;
- for (j = 0; j<n-jump; j++) {
- i = j + jump;
- item1 = i+fromItem;
- item2 = j+fromItem;
- /* get menu item 1 data */
- GetItem(pMenu, item1, itemText1);
- GetItemMark(pMenu, item1, &mark1);
- GetItemCmd(pMenu, item1, &cmd1);
- /* get menu item 2 data */
- GetItem(pMenu, item2, itemText2);
- GetItemMark(pMenu, item2, &mark2);
- GetItemCmd(pMenu, item2, &cmd2);
- if (IUCompString(itemText2, itemText1) > 0) {
- /* swap item data */
- SetItem(pMenu, item1, itemText2);
- SetItemMark(pMenu, item1, mark2);
- SetItemCmd(pMenu, item1, cmd2);
- SetItem(pMenu, item2, itemText1);
- SetItemMark(pMenu, item2, mark1);
- SetItemCmd(pMenu, item2, cmd1);
- /* fix the auto receives */
- swapAutoCom(pmp, mID, item1, mID, item2);
- /* fix the pList */
- for (k = 0; k<pmp->pCount; k++) {
- if (pmID == mID) {
- /* look at the itemID */
- if (pmp->pList[k].itemID == item1) {
- pmp->pList[k].itemID = item2;
- }
- else if (pmp->pList[k].itemID == item2) {
- pmp->pList[k].itemID = item1;
- }
- }
- else {
- /* look for hierarchical menu item and hierarchical ID */
- if (pmp->pList[k].HmenuID == mID) {
- if (pmp->pList[k].HitemID == item1) {
- pmp->pList[k].HitemID = item2;
- }
- else if (pmp->pList[k].HitemID == item2) {
- pmp->pList[k].HitemID = item1;
- }
- }
- }
- }
- done = FALSE;
- }
- }
- } while(!done);
- }
- }
-
- GetSubFunction(SFP, ID, index)
- register ProcSub *SFP;
- int ID;
- register int index;
- {
- int sCount;
- PInfHandle pInf;
- register unsigned char *sfp;
- /* set default for not found condition */
- SFP->pFlags = 0;
- SFP->refCon = 0;
- SFP->subName[0] = 0;
- /* try to get the resource */
- pInf = (PInfHandle) GetResource('PInf', ID);
- if (pInf) {
- /* get the number of sub functions described in the resource */
- sCount = (*pInf)->SubCount;
- if ((sCount > 0) && (sCount >= index)) {
- sfp = (unsigned char *) *pInf;
- /* bump past the count word */
- sfp += 2;
- /* bump through sub descriptions until we get to the right one */
- while (--index) {
- /* bump past the non-string stuff */
- sfp = (unsigned char *) (&(((ProcSub *) sfp)->subName));
- /* bump past the name string (with padding) */
- sfp += *sfp+2-(*sfp & 1);
- /* bump past the auto string (with padding) */
- sfp += *sfp+2-(*sfp & 1);
- }
- /* extract the data */
- SFP->pFlags = ((ProcSub *) sfp)->pFlags;
- SFP->refCon = ((ProcSub *) sfp)->refCon;
- sfp = (unsigned char *) (&(((ProcSub *) sfp)->subName));
- Pstrcpy(SFP->subName, sfp);
- sfp += *sfp+2-(*sfp & 1);
- Pstrcpy(SFP->autoCom, sfp);
- }
- }
- }
-
- addAutoCom(pmp, menuSelect, autoComs)
- register ProcMenuPtr pmp;
- long menuSelect;
- unsigned char *autoComs;
- {
- register int i;
- Str255 autoStr;
- long offset, size;
- register AutoComPtr acp;
- autoStr[0] = 0;
- for (i = 1; i<=autoComs[0]; i++) {
- if (autoComs[i] != ',') {
- Pstrcad(autoStr, autoComs[i]);
- }
- else if ((i < autoComs[0]) && (autoComs[i+1] == ',')) {
- Pstrcad(autoStr, autoComs[i]);
- continue;
- }
- if (autoStr[0] && ((i == autoComs[0]) || (autoComs[i] == ','))) {
- /* add the auto string */
- offset = GetHandleSize(pmp->autoComs);
- size = sizeof(AutoComRec)+autoStr[0]+2-(autoStr[0] & 1);
- SetHandleSize(pmp->autoComs, offset+size);
- acp = (AutoComPtr) (((unsigned char *) *pmp->autoComs) + offset);
- acp->matchChar = 1;
- acp->menuSelect = menuSelect;
- Pstrcpy(acp->autoCom, autoStr);
- ++pmp->autoCount;
- autoStr[0] = 0;
- }
- }
- }
-
- swapAutoCom(pmp, menuSelect1, menuSelect2)
- register ProcMenuPtr pmp;
- long menuSelect1, menuSelect2;
- {
- register int i;
- register unsigned char *acp;
- acp = (unsigned char *) *pmp->autoComs;
- for (i = 0; i<pmp->autoCount; i++) {
- if (((AutoComPtr) acp)->menuSelect == menuSelect1) {
- ((AutoComPtr) acp)->menuSelect = menuSelect2;
- }
- else if (((AutoComPtr) acp)->menuSelect == menuSelect2) {
- ((AutoComPtr) acp)->menuSelect = menuSelect1;
- }
- /* bump past the non-string stuff */
- acp = (unsigned char *) (&(((AutoComPtr) acp)->autoCom));
- /* bump past the auto string (with padding) */
- acp += *acp+2-(*acp & 1);
- }
- }
-
- doHelp(update)
- void (*update)();
- {
- int item;
- long callHelp();
- Block_Record hRec;
- pascal void DealUpdates();
- Pstrcpy(hRec.message,
- "\p\rProtocol Interface\rCopyright © 1990 by John Raymonds");
- Pstrcat(hRec.message,
- "\p\r\rHelp System\rCopyright © 1989 By Eric Berman");
- hRec.Help_Type = 'Thlp';
- hRec.Num_Types = 1;
- hRec.Res_Types = (ResType *) "Thlp";
- SetPt(&hRec.upper_Left, 0, 0);
- hRec.update_Proc = update;
- hRec.map_Hook = 0L;
- /* get list of topics */
- hRec.topic_List = (Help_List_Handle)
- callHelp(&hRec, GetTopicList_Trap);
- if (hRec.topic_List) {
- /* and sort them */
- callHelp(&hRec, ShellSort_Trap);
- /* display the help items */
- hRec.Dialog_ID = Text_List_ID;
- hRec.the_Help = (Handle) callHelp(&hRec, TextMenu_Trap);
- /* do event loop for help system */
- do {
- hRec.Dialog_ID = Topic_Window_ID;
- item = callHelp(&hRec, ShowTopicList_Trap);
- if (item == 2) {
- /* display the help items */
- hRec.Dialog_ID = Text_List_ID;
- hRec.the_Help = (Handle) callHelp(&hRec, TextMenu_Trap);
- }
- } while(item != 1);
- DisposHandle(hRec.topic_List);
- }
- }
-
- long callHelp(hRecPtr, theMessage)
- register Block_Ptr hRecPtr;
- int theMessage;
- {
- long gtl();
- register long result;
- register long (**the_Code)();
- result = 0L;
- if (theMessage == GetTopicList_Trap) {
- return(gtl(hRecPtr));
- }
- hRecPtr->varCode = theMessage;
- the_Code = (long (** )()) GetResource('PROC', 901);
- if (the_Code) {
- MoveHHi(the_Code);
- HLock(the_Code);
- result = CallPascalL(hRecPtr, *the_Code);
- HUnlock(the_Code);
- }
- return(result);
- }
-
- long gtl(hRecPtr)
- register Block_Ptr hRecPtr;
- {
- Handle rHand;
- Help_List_Handle hHand;
- register int Num_Topics, i;
- register Help_List_Ptr hPtr;
- /* my code can only handle one help type */
- hHand = 0L;
- Num_Topics = Count1Resources(*hRecPtr->Res_Types);
- if (Num_Topics) {
- hHand = (Help_List_Handle)
- NewHandle((long) (sizeof(Help_List_Type) * Num_Topics));
- if (hHand) {
- HLock(hHand);
- hPtr = *hHand;
- SetResLoad(FALSE);
- for (i = 0; i<Num_Topics; i++) {
- rHand = Get1IndResource(*hRecPtr->Res_Types, i+1);
- if (rHand) {
- GetResInfo(rHand, &hPtr[i].help_ID,
- &hPtr[i].help_Type, &hPtr[i].help_String);
- }
- }
- SetResLoad(TRUE);
- HUnlock(hHand);
- }
- }
- return((long) hHand);
- }
-